<?php
/**
 * 定义 milkphp核心类
 *
 * @link http://www.milkphp.com/
 * @author donwa <donwa@milkphp.com>
 * @license New BSD License {@link http://www.milkhphp.com/license/}
 * 
 */
class lib_milkphp{
	static $dir;
	
	function __construct(){
		$this->dir = array(
			'data'=>M_DIR.'data/',
			'mod'=>M_DIR.'module/',
			'tmp'=>M_DIR.'tmp/',
		);
	}
	
	/**
	 * 程序运行时间
	 * @return float 返回程序运行时间
	 */
	function runTime(){
		return microtime() - M_TIME;
	}
	
	/**
	 * 执行函数，返回一个唯一milkphp实例
	 */
	static function _do(){
		static $instance = NULL;
		if(!is_null($instance))return $instance;
		return $instance = new lib_milkphp();
	}
	
	/**
	 * 魔术方法call
	 * 
	 * @code
	 * m()->test();#调用lib_test::_do()方法
	 * @endcode
	 * @return mixed;
	 */
	private function __call($name,$arguments){
		/**
		 * 判断调用类是否存在(static) _do函数
		 */
		//$name = strtolower($name);
		if(method_exists('lib_'.$name,'_do')){
			return call_user_func_array(array("lib_$name","_do"),$arguments);
		}else{
			static $instance = array();
			if(!is_null($instance[$name]))return $instance[$name];
				$className = 'lib_'.$name;
				return $instance[$name] = new $className();
			m()->debug('e','lib_'.$name.'无_do函数');
		}
	}
}